package com.swx.generate.bean;

import com.alibaba.fastjson.JSON;
import com.swx.generate.jmxBean.Argument;
import com.swx.generate.jmxBean.File;
import com.swx.generate.jmxBean.Header;
import lombok.Data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Data
//@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class Path {
    private String url;
    private String method;
    private String summary;
    private String description;
    private String consumes;
    private Object properties;
    private Object respones;

    private boolean autoRedirects = false;
    private boolean followRedirects = true;
    private boolean useKeepalive = true;
    private boolean DO_MULTIPART_POST = false;
    private boolean BROWSER_COMPATIBLE_MULTIPART = false;

    private final List<File> files = new ArrayList<>();
    private final List<Header> headers = new ArrayList<>();
    private final List<Argument> arguments = new ArrayList<>();

    public boolean addFile(File file) {
        Iterator<Header> iterator = headers.iterator();
        while (iterator.hasNext()) {
            Header header = iterator.next();
            if ("content-type".equals(header.getName())) {
                iterator.remove();
                break;
            }
        }
        return files.add(file);
    }

    public boolean addHeader(Header header) {
        return headers.add(header);
    }

    public boolean addArgument(Argument argument) {
        return arguments.add(argument);
    }

    public String getTestname() {
        return summary;
    }

    public String getPath() {
        return url;
    }

    public String getValue() {
        return JSON.toJSONString(properties, true);
    }

    public String getResponesValue() {
        return JSON.toJSONString(respones, true);
    }

    public String getComments() {
        return description;
    }
}
